export function safeParse(
  text: string,
  reviver?: (this: any, key: string, value: any) => any | undefined,
  returnArrayType?: boolean,
) {
  try {
    return JSON.parse(text, reviver);
  } catch (error) {
    return returnArrayType ? [] : {};
  }
}

export function safeJsonParse(
  text: string,
  options?: {
    reviver?: (this: any, key: string, value: any) => any | undefined;
    returnArrayType?: boolean;
  },
) {
  const { reviver, returnArrayType } = options || {};
  try {
    return JSON.parse(text, reviver);
  } catch (error) {
    return returnArrayType ? [] : {};
  }
}
